package org.jeecg.modules.wmhb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.constant.UserConstant;
import org.jeecg.modules.wmhb.entity.*;
import org.jeecg.modules.wmhb.mapper.WmPurchaseOrderDetailDyMapper;
import org.jeecg.modules.wmhb.service.IWmPurchaseOrderDetailDyService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;
import java.util.List;

/**
 * @Description: 电仪订货明细
 * @Author: jeecg-boot
 * @Date:   2025-02-26
 * @Version: V1.0
 */
@Service
public class WmPurchaseOrderDetailDyServiceImpl extends ServiceImpl<WmPurchaseOrderDetailDyMapper, WmPurchaseOrderDetailDy> implements IWmPurchaseOrderDetailDyService {
    @Override
    public void arriveBatch(List<String> idList, String factArriveTime){
        LambdaUpdateWrapper<WmPurchaseOrderDetailDy> updateWrapper = new LambdaUpdateWrapper<>();
        if(StringUtils.isEmpty(factArriveTime)){
            updateWrapper.set(WmPurchaseOrderDetailDy::getFactArriveTime, new Date());
        }
        else{
            updateWrapper.set(WmPurchaseOrderDetailDy::getFactArriveTime, factArriveTime);
        }

        updateWrapper.in(WmPurchaseOrderDetailDy::getId, idList);
        update(null, updateWrapper);
    };

    @Override
    public List<WmPurchaseOrderDetailDy> searchBySeriesNo(String seriesNo){
        LambdaQueryWrapper<WmPurchaseOrderDetailDy> queryWrapperTask = new LambdaQueryWrapper<>();
        queryWrapperTask.eq(WmPurchaseOrderDetailDy::getSeriesNo, seriesNo);
        List<WmPurchaseOrderDetailDy> wmPurchaseOrderDetailDyList = list(queryWrapperTask);
        return wmPurchaseOrderDetailDyList;
    };

    @Override
    public List<WmPurchaseOrderDetailDy> searchBySeriesNoAndRemark(String seriesNo, String remark){
        LambdaQueryWrapper<WmPurchaseOrderDetailDy> queryWrapperTask = new LambdaQueryWrapper<>();
        queryWrapperTask.eq(WmPurchaseOrderDetailDy::getSeriesNo, seriesNo);
        if(!StringUtils.isEmpty(remark)){
            queryWrapperTask.eq(WmPurchaseOrderDetailDy::getRemark, remark);
        }
        else{
            queryWrapperTask.isNull(WmPurchaseOrderDetailDy::getRemark);
        }
        List<WmPurchaseOrderDetailDy> wmPurchaseOrderDetailDyList = list(queryWrapperTask);
        return wmPurchaseOrderDetailDyList;
    };

    @Override
    public void updateBySeriesNoAndRemark(WmPurchaseOrderDetailDy wmPurchaseOrderDetailDy){
        LambdaUpdateWrapper<WmPurchaseOrderDetailDy> updateWrapper = new LambdaUpdateWrapper<>();
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getQuantity())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getQuantity, wmPurchaseOrderDetailDy.getQuantity())
                    .set(WmPurchaseOrderDetailDy::getArriveQuantity, wmPurchaseOrderDetailDy.getArriveQuantity());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getPurchaseOrderNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getPurchaseOrderNo, wmPurchaseOrderDetailDy.getPurchaseOrderNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getJdContractNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getJdContractNo, wmPurchaseOrderDetailDy.getJdContractNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getJdOrderNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getJdOrderNo, wmPurchaseOrderDetailDy.getJdOrderNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getOrderNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getOrderNo, wmPurchaseOrderDetailDy.getOrderNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getOrderDate())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getOrderDate, wmPurchaseOrderDetailDy.getOrderDate());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getFactArriveTime())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getFactArriveTime, wmPurchaseOrderDetailDy.getFactArriveTime());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getJdNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getJdNo, wmPurchaseOrderDetailDy.getJdNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getTaskNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getTaskNo, wmPurchaseOrderDetailDy.getTaskNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getContractNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getContractNo, wmPurchaseOrderDetailDy.getContractNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getPurchaseNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getPurchaseNo, wmPurchaseOrderDetailDy.getPurchaseNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getProjectInfo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getProjectInfo, wmPurchaseOrderDetailDy.getProjectInfo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getReceiver())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getReceiver, wmPurchaseOrderDetailDy.getReceiver());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorAPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorAPrice, wmPurchaseOrderDetailDy.getVendorAPrice());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorBPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorBPrice, wmPurchaseOrderDetailDy.getVendorBPrice());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorCPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorCPrice, wmPurchaseOrderDetailDy.getVendorCPrice());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorDPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorDPrice, wmPurchaseOrderDetailDy.getVendorDPrice());
        }

        updateWrapper.eq(WmPurchaseOrderDetailDy::getSeriesNo, wmPurchaseOrderDetailDy.getSeriesNo());
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getRemark())){
            updateWrapper.eq(WmPurchaseOrderDetailDy::getRemark, wmPurchaseOrderDetailDy.getRemark());
        }
        else{
            updateWrapper.isNull(WmPurchaseOrderDetailDy::getRemark);
        }
        update(null, updateWrapper);
    };

    @Override
    public List<WmPurchaseOrderDetailDy> searchByContractAndJdName(String contractNo, String jdName){
        LambdaQueryWrapper<WmPurchaseOrderDetailDy> queryWrapperTask = new LambdaQueryWrapper<>();
        queryWrapperTask.eq(WmPurchaseOrderDetailDy::getContractNo, contractNo).eq(WmPurchaseOrderDetailDy::getJdName, jdName);
        List<WmPurchaseOrderDetailDy> wmPurchaseOrderDetailList = list(queryWrapperTask);
        return wmPurchaseOrderDetailList;
    };

    @Override
    public void updateByContractAndJdName(WmPurchaseOrderDetailDy wmPurchaseOrderDetailDy){
        LambdaUpdateWrapper<WmPurchaseOrderDetailDy> updateWrapper = new LambdaUpdateWrapper<>();
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getQuantity())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getQuantity, wmPurchaseOrderDetailDy.getQuantity());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getPurchaseOrderNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getPurchaseOrderNo, wmPurchaseOrderDetailDy.getPurchaseOrderNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getJdContractNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getJdContractNo, wmPurchaseOrderDetailDy.getJdContractNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getJdOrderNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getJdOrderNo, wmPurchaseOrderDetailDy.getJdOrderNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getOrderNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getOrderNo, wmPurchaseOrderDetailDy.getOrderNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getOrderDate())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getOrderDate, wmPurchaseOrderDetailDy.getOrderDate());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getFactArriveTime())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getFactArriveTime, wmPurchaseOrderDetailDy.getFactArriveTime());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getJdNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getJdNo, wmPurchaseOrderDetailDy.getJdNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getTaskNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getTaskNo, wmPurchaseOrderDetailDy.getTaskNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getContractNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getContractNo, wmPurchaseOrderDetailDy.getContractNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getPurchaseNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getPurchaseNo, wmPurchaseOrderDetailDy.getPurchaseNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getProjectInfo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getProjectInfo, wmPurchaseOrderDetailDy.getProjectInfo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getReceiver())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getReceiver, wmPurchaseOrderDetailDy.getReceiver());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorAPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorAPrice, wmPurchaseOrderDetailDy.getVendorAPrice());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorBPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorBPrice, wmPurchaseOrderDetailDy.getVendorBPrice());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorCPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorCPrice, wmPurchaseOrderDetailDy.getVendorCPrice());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorDPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorDPrice, wmPurchaseOrderDetailDy.getVendorDPrice());
        }

        updateWrapper.eq(WmPurchaseOrderDetailDy::getContractNo, wmPurchaseOrderDetailDy.getContractNo()).eq(WmPurchaseOrderDetailDy::getJdName, wmPurchaseOrderDetailDy.getJdName());
        update(null, updateWrapper);
    };

    @Override
    public List<WmPurchaseOrderDetailDy> searchByJdOrderAndJdName(String jdOrderNo, String jdName){
        LambdaQueryWrapper<WmPurchaseOrderDetailDy> queryWrapperTask = new LambdaQueryWrapper<>();
        queryWrapperTask.eq(WmPurchaseOrderDetailDy::getJdOrderNo, jdOrderNo).eq(WmPurchaseOrderDetailDy::getJdName, jdName);
        List<WmPurchaseOrderDetailDy> wmPurchaseOrderDetailList = list(queryWrapperTask);
        return wmPurchaseOrderDetailList;
    };

    @Override
    public void updateByJdOrderAndJdName(WmPurchaseOrderDetailDy wmPurchaseOrderDetailDy){
        LambdaUpdateWrapper<WmPurchaseOrderDetailDy> updateWrapper = new LambdaUpdateWrapper<>();
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getQuantity())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getQuantity, wmPurchaseOrderDetailDy.getQuantity());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getPurchaseOrderNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getPurchaseOrderNo, wmPurchaseOrderDetailDy.getPurchaseOrderNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getJdContractNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getJdContractNo, wmPurchaseOrderDetailDy.getJdContractNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getJdOrderNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getJdOrderNo, wmPurchaseOrderDetailDy.getJdOrderNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getOrderNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getOrderNo, wmPurchaseOrderDetailDy.getOrderNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getOrderDate())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getOrderDate, wmPurchaseOrderDetailDy.getOrderDate());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getFactArriveTime())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getFactArriveTime, wmPurchaseOrderDetailDy.getFactArriveTime());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getJdNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getJdNo, wmPurchaseOrderDetailDy.getJdNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getTaskNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getTaskNo, wmPurchaseOrderDetailDy.getTaskNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getContractNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getContractNo, wmPurchaseOrderDetailDy.getContractNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getPurchaseNo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getPurchaseNo, wmPurchaseOrderDetailDy.getPurchaseNo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getProjectInfo())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getProjectInfo, wmPurchaseOrderDetailDy.getProjectInfo());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getReceiver())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getReceiver, wmPurchaseOrderDetailDy.getReceiver());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorAPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorAPrice, wmPurchaseOrderDetailDy.getVendorAPrice());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorBPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorBPrice, wmPurchaseOrderDetailDy.getVendorBPrice());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorCPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorCPrice, wmPurchaseOrderDetailDy.getVendorCPrice());
        }
        if(!StringUtils.isEmpty(wmPurchaseOrderDetailDy.getVendorDPrice())){
            updateWrapper.set(WmPurchaseOrderDetailDy::getVendorDPrice, wmPurchaseOrderDetailDy.getVendorDPrice());
        }

        updateWrapper.eq(WmPurchaseOrderDetailDy::getJdOrderNo, wmPurchaseOrderDetailDy.getJdOrderNo()).eq(WmPurchaseOrderDetailDy::getJdName, wmPurchaseOrderDetailDy.getJdName());
        update(null, updateWrapper);
    };

    @Override
    public List<WmPurchaseOrderDetailDy> queryNoSeriesNoOfPurchaseBom(){
        LambdaQueryWrapper<WmPurchaseOrderDetailDy> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.isNull(WmPurchaseOrderDetailDy::getSeriesNo).eq(WmPurchaseOrderDetailDy::getIsCheckPurchaseBom, UserConstant.SYS_NO);
        List<WmPurchaseOrderDetailDy> wmPurchaseOrderDetailDyList = list(queryWrapper);
        return wmPurchaseOrderDetailDyList;
    };

    @Override
    public List<WmPurchaseOrderDetailDy> queryNoSeriesNoOfTaskBom(WmTaskBom wmTaskBom, WmTaskbook wmTaskbook){
        LambdaQueryWrapper<WmPurchaseOrderDetailDy> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.isNull(WmPurchaseOrderDetailDy::getSeriesNo)
                .eq(WmPurchaseOrderDetailDy::getIsCheckTaskBom, UserConstant.SYS_NO)
                .eq(WmPurchaseOrderDetailDy::getJdName, wmTaskBom.getName())
                .eq(WmPurchaseOrderDetailDy::getTaskNo, wmTaskbook.getCode());
        List<WmPurchaseOrderDetailDy> wmPurchaseOrderDetailDyList = list(queryWrapper);
        return wmPurchaseOrderDetailDyList;
    };
}
